package org.e_gold.dao.impl;

import org.apache.commons.collections.CollectionUtils;
import org.e_gold.dao.UserAccountDAO;
import org.e_gold.model.UserAccount;
import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class UserAccountDAOImpl extends AbstractGenericDAO<UserAccount> implements UserAccountDAO {

	public UserAccountDAOImpl() {

		super(UserAccount.class);
	}

	@Override
	@Transactional
	public UserAccount getCurrentUser() {

		Criteria criteria = getCurrentSession().createCriteria(UserAccount.class);
		criteria.setFirstResult(0);
		if (CollectionUtils.isNotEmpty(criteria.list())) {
			return (UserAccount) criteria.list().get(0);
		}
		return null;
	}
}
